#ifndef NETWORK_H_INCLUDED
#define NETWORK_H_INCLUDED

#include <iostream>
#include <queue>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>

#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <SFML/Network.hpp>

#include "serv_maps.h"

struct functions
{
	int id;
	std::string function;
	std::string argument;
	std::string variable;
};

struct character
{
	std::string charname;
	int level;
	int money;
	int rank;
	int map;
	int x;
	int y;
	int party;
	int guild;
	int hp;
	int mp;
	int maxhp;
	int maxmp;
	std::vector<int> equip;
	std::vector<int> inventory;
};

class Network
{
    public:
		Network();

		void Connect();
		void Close();
		bool status();
		void SetStatus(bool status);
		void Refresh();
		void ReceivePackets();
		void SendPackets();
		void NewPacket(int id, std::string function, std::string argument, std::string variable);
		void NewQuery(std::string query);
		void Ping();

        void Login(int id, std::string username, std::string password);
        void SelectChar(int id, std::string slot);
        /*void CreateChar(std::queue<struct QueuedItem> &QueueToSend, struct QueuedItem ToReceive, std::vector<int> &ClientStatusVector, std::vector<int> &ClientIDVector);
        void DeleteChar(std::queue<struct QueuedItem> &QueueToSend, struct QueuedItem ToReceive, std::vector<int> &ClientStatusVector, std::vector<int> &ClientIDVector);*/
        void Message(int id, std::string message);
        void Move(int id, int x, int y);
		void NextMove(int id);
		/*void UpdateItem(std::queue<struct QueuedItem> &QueueToSend, struct QueuedItem ToReceive, std::vector<int> &ClientStatusVector, std::vector<int> &ClientIDVector, sql::Statement *stmt);*/
        void Disconnect(int id);

	private:
		std::vector<Maps> m_mapsVector;
		std::vector< std::vector<Node> > m_charPath;

		std::map<std::string, int> m_charid;
		std::map<int, struct character> m_charInfo;

		std::vector<sf::SocketTCP> m_socketList;

		std::queue<struct functions> m_packetsToSend;
		std::queue<struct functions> m_packetsToReceive;

		sf::SelectorTCP m_selector;
		sf::SocketTCP m_listener;

		sql::Driver *driver;
		sql::Connection	*con;
		sql::Statement *stmt;

		bool m_status;
};

#endif // NETWORK_H_INCLUDED
